﻿using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Virvar.Net;
using System.Threading;

namespace UDPServer
{
    class Program
    {
        static Encoding enc = Encoding.Default;

        static void Main(string[] args)
        {
            IMessager messager = new UdpMessager("127.0.0.1", 7777, 7778);
            Console.WriteLine("Это сервер.");
            while (true)
            {
                byte[] bytes = messager.Receive();
                if (bytes == null)
                    break;
                string text = "server: " + enc.GetString(bytes);
                Console.WriteLine(text);
                messager.Send(enc.GetBytes(text));
            }
            Console.WriteLine("Жми для выхода!");
            Console.ReadKey();
            //UdpClient sender = new UdpClient();
            //try
            //{
            //    sender.Connect("localhost", port);
            //    byte[] data = enc.GetBytes("Hello World!");
            //    sender.Send(data, data.Length);
            //    sender.Close();
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine("Error : " + e);
            //}
        }
    }
}
